roundedbox: Add gtk_rounded_boxes_init_for_style()
authorBenjamin Otte <otte@redhat.com>
Mon, 19 Dec 2016 18:19:15 +0000 (19:19 +0100)
committerBenjamin Otte <otte@redhat.com>
Tue, 20 Dec 2016 17:01:12 +0000 (18:01 +0100)
Instead of making people intiialize a rectangle and then applying border
radius manually, provide a constructor that does it for them.
While doing that, also allow people to instead request the padding box
or the content box.

Refactor all relevant code to use this new constructor.

13 files changed:
docs/reference/gtk/Makefile.am
gtk/Makefile.am
gtk/gtkcolorscale.c
gtk/gtkcolorswatch.c
gtk/gtkcssimagebuiltin.c
gtk/gtkcssshadowvalue.c
gtk/gtkpopover.c
gtk/gtkrender.c
gtk/gtkrenderbackground.c
gtk/gtkrenderborder.c
gtk/gtkrenderprivate.h [deleted file]
gtk/gtkroundedbox.c
gtk/gtkroundedboxprivate.h

index 300c5859e2abd819cd8997b44bacba0ecbae4c2d..e02fc818b884a9a44c2977b270d53e4f4f258de0 100644 (file)
@@ -166,7 +166,6 @@ IGNORE_HFILES = \
        gtkrenderbackgroundprivate.h    \
        gtkrenderborderprivate.h        \
        gtkrendericonprivate.h          \
-       gtkrenderprivate.h              \
        gtkroundedboxprivate.h          \
        gtkscaleprivate.h               \
        gtksearchengine.h               \
index 2578e1f5f2e75796b31c907f4cd92cd51eb2d1d9..bdb489859e123e4492a1ab155210b0f62b5b9715 100644 (file)
@@ -526,7 +526,6 @@ gtk_private_h_sources =             \
        gtkrenderbackgroundprivate.h \
        gtkrenderborderprivate.h \
        gtkrendericonprivate.h  \
-       gtkrenderprivate.h      \
        gtkresources.h          \
        gtkroundedboxprivate.h  \
        gtksearchengine.h       \
index b6560a76fc61c02e2842292a828bcca538893a5a..b8564ae13a85d183485670f89dec8ba0c117516b 100644 (file)
@@ -28,7 +28,6 @@
 #include "gtkaccessible.h"
 #include "gtkprivate.h"
 #include "gtkintl.h"
-#include "gtkrenderprivate.h"
 #include "gtksnapshot.h"
 
 #include <math.h>
index 15f6b6c73d9ebbc178213e298842ded9eea18b98..9c957541899ba9f3820b9e94b590bb2482fb6f2e 100644 (file)
 #include "gtkmenushell.h"
 #include "gtkprivate.h"
 #include "gtkintl.h"
-#include "gtkrenderprivate.h"
 #include "gtkiconhelperprivate.h"
 #include "gtkcssnodeprivate.h"
 #include "gtkcsscustomgadgetprivate.h"
+#include "gtkroundedboxprivate.h"
 #include "gtkwidgetprivate.h"
 #include "gtkstylecontextprivate.h"
 #include "a11y/gtkcolorswatchaccessibleprivate.h"
 
+#include "gsk/gskroundedrectprivate.h"
 
 /*
  * GtkColorSwatch has two CSS nodes, the main one named colorswatch
@@ -120,6 +121,7 @@ gtk_color_swatch_render (GtkCssGadget *gadget,
       cairo_pattern_t *pattern;
       cairo_matrix_t matrix;
       GtkAllocation allocation, border_allocation;
+      GskRoundedRect content_box;
 
       gtk_widget_get_allocation (widget, &allocation);
       gtk_css_gadget_get_border_allocation (gadget, &border_allocation, NULL);
@@ -127,11 +129,15 @@ gtk_color_swatch_render (GtkCssGadget *gadget,
       border_allocation.x -= allocation.x;
       border_allocation.y -= allocation.y;
 
-      gtk_render_content_path (context, cr,
-                               border_allocation.x,
-                               border_allocation.y,
-                               border_allocation.width,
-                               border_allocation.height);
+      gtk_rounded_boxes_init_for_style (NULL,
+                                        NULL,
+                                        &content_box,
+                                        gtk_style_context_lookup_style (context),
+                                        border_allocation.x,
+                                        border_allocation.y,
+                                        border_allocation.width,
+                                        border_allocation.height);
+      gsk_rounded_rect_path (&content_box, cr);
 
       if (swatch->priv->use_alpha)
         {
index 00a267ca1a6621d76e23607745b6939a767641bf..67cc0614722393381d5412af22ba9631d5eb5ac1 100644 (file)
@@ -26,7 +26,6 @@
 #include "gtkcssrgbavalueprivate.h"
 #include "gtkcssstyleprivate.h"
 #include "gtkhslaprivate.h"
-#include "gtkrenderprivate.h"
 
 #include <math.h>
 
index d9e1aaa3fb289fbe8f4ce0621ff28527956aaed0..bcb874db98e0f5f358872e82449340d716ed70b5 100644 (file)
@@ -26,7 +26,6 @@
 #include "gtkcssrgbavalueprivate.h"
 #include "gtksnapshot.h"
 #include "gtkstylecontextprivate.h"
-#include "gtkrenderprivate.h"
 #include "gtkpango.h"
 
 #include "gsk/gskcairoblurprivate.h"
index 6e8ba94c96a30aaa9df6a2ced3d50dd7d034a28a..48778fb95493aab795eb11b6ecbd130d67ac0229 100644 (file)
@@ -918,9 +918,10 @@ gtk_popover_fill_border_path (GtkPopover *popover,
 
   gtk_popover_get_rect_coords (popover, &x, &y, &w, &h);
 
-  _gtk_rounded_box_init_rect (&box, x, y, w, h);
-  _gtk_rounded_box_apply_border_radius_for_style (&box,
-                                                  gtk_style_context_lookup_style (context));
+  gtk_rounded_boxes_init_for_style (&box,
+                                    NULL, NULL,
+                                    gtk_style_context_lookup_style (context),
+                                    x, y, w, h);
   gsk_rounded_rect_path (&box, cr);
   cairo_fill (cr);
 }
index 7ff34275de0b1c8751c8c2dd1b579ce3f381fa1e..3d4bbbaf3e934c275840a8cb47b21575f7b0f808 100644 (file)
@@ -18,7 +18,6 @@
 #include "config.h"
 
 #include "gtkrender.h"
-#include "gtkrenderprivate.h"
 
 #include <math.h>
 
@@ -914,47 +913,3 @@ gtk_render_icon_surface (GtkStyleContext *context,
                                      x, y);
 }
 
-/*
- * gtk_render_content_path:
- * @context: style context to get style information from
- * @cr: cairo context to add path to
- * @x: x coordinate of CSS box
- * @y: y coordinate of CSS box
- * @width: width of CSS box
- * @height: height of CSS box
- *
- * Adds the path of the content box to @cr for a given border box.
- * This function respects rounded corners.
- *
- * This is useful if you are drawing content that is supposed to
- * fill the whole content area, like the color buttons in
- * #GtkColorChooserDialog.
- **/
-void
-gtk_render_content_path (GtkStyleContext *context,
-                         cairo_t         *cr,
-                         double           x,
-                         double           y,
-                         double           width,
-                         double           height)
-{
-  GskRoundedRect box;
-
-  g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
-  g_return_if_fail (cr != NULL);
-
-  _gtk_rounded_box_init_rect (&box, x, y, width, height);
-  _gtk_rounded_box_apply_border_radius_for_style (&box, gtk_style_context_lookup_style (context));
-
-  gsk_rounded_rect_shrink (&box,
-                           _gtk_css_number_value_get (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_BORDER_TOP_WIDTH), 100)
-                           + _gtk_css_number_value_get (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_PADDING_TOP), 100),
-                           _gtk_css_number_value_get (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_BORDER_RIGHT_WIDTH), 100)
-                           + _gtk_css_number_value_get (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_PADDING_RIGHT), 100),
-                           _gtk_css_number_value_get (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_BORDER_BOTTOM_WIDTH), 100)
-                           + _gtk_css_number_value_get (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_PADDING_BOTTOM), 100),
-                           _gtk_css_number_value_get (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_BORDER_LEFT_WIDTH), 100)
-                           + _gtk_css_number_value_get (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_PADDING_LEFT), 100));
-
-  gsk_rounded_rect_path (&box, cr);
-}
index ae80f5fefca6936913ad2794a088a22ffc57b055..051a9fddd1026c88c4ad456568ff1aee3b0b4a1b 100644 (file)
@@ -529,39 +529,13 @@ gtk_theming_background_init (GtkThemingBackground *bg,
                              double                width,
                              double                height)
 {
-  GtkBorder border, padding;
-
   bg->style = style;
 
-  border.top = _gtk_css_number_value_get (gtk_css_style_get_value (bg->style, GTK_CSS_PROPERTY_BORDER_TOP_WIDTH), 100);
-  border.right = _gtk_css_number_value_get (gtk_css_style_get_value (bg->style, GTK_CSS_PROPERTY_BORDER_RIGHT_WIDTH), 100);
-  border.bottom = _gtk_css_number_value_get (gtk_css_style_get_value (bg->style, GTK_CSS_PROPERTY_BORDER_BOTTOM_WIDTH), 100);
-  border.left = _gtk_css_number_value_get (gtk_css_style_get_value (bg->style, GTK_CSS_PROPERTY_BORDER_LEFT_WIDTH), 100);
-  padding.top = _gtk_css_number_value_get (gtk_css_style_get_value (bg->style, GTK_CSS_PROPERTY_PADDING_TOP), 100);
-  padding.right = _gtk_css_number_value_get (gtk_css_style_get_value (bg->style, GTK_CSS_PROPERTY_PADDING_RIGHT), 100);
-  padding.bottom = _gtk_css_number_value_get (gtk_css_style_get_value (bg->style, GTK_CSS_PROPERTY_PADDING_BOTTOM), 100);
-  padding.left = _gtk_css_number_value_get (gtk_css_style_get_value (bg->style, GTK_CSS_PROPERTY_PADDING_LEFT), 100);
-
-  /* In the CSS box model, by default the background positioning area is
-   * the padding-box, i.e. all the border-box minus the borders themselves,
-   * which determines also its default size, see
-   * http://dev.w3.org/csswg/css3-background/#background-origin
-   *
-   * In the future we might want to support different origins or clips, but
-   * right now we just shrink to the default.
-   */
-  _gtk_rounded_box_init_rect (&bg->boxes[GTK_CSS_AREA_BORDER_BOX], 0, 0, width, height);
-  _gtk_rounded_box_apply_border_radius_for_style (&bg->boxes[GTK_CSS_AREA_BORDER_BOX], bg->style);
-
-  bg->boxes[GTK_CSS_AREA_PADDING_BOX] = bg->boxes[GTK_CSS_AREA_BORDER_BOX];
-  gsk_rounded_rect_shrink (&bg->boxes[GTK_CSS_AREA_PADDING_BOX],
-                          border.top, border.right,
-                          border.bottom, border.left);
-
-  bg->boxes[GTK_CSS_AREA_CONTENT_BOX] = bg->boxes[GTK_CSS_AREA_PADDING_BOX];
-  gsk_rounded_rect_shrink (&bg->boxes[GTK_CSS_AREA_CONTENT_BOX],
-                          padding.top, padding.right,
-                          padding.bottom, padding.left);
+  gtk_rounded_boxes_init_for_style (&bg->boxes[GTK_CSS_AREA_BORDER_BOX],
+                                    &bg->boxes[GTK_CSS_AREA_PADDING_BOX],
+                                    &bg->boxes[GTK_CSS_AREA_CONTENT_BOX],
+                                    style,
+                                    0, 0, width, height);
 }
 
 void
index 429ae39c73973d332c886698888642aa1b9ec34e..d6223c441fbdad62a40f00a10b615adc23f39693 100644 (file)
@@ -912,8 +912,7 @@ gtk_css_style_render_border (GtkCssStyle *style,
       colors[2] = *_gtk_css_rgba_value_get_rgba (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_BORDER_BOTTOM_COLOR));
       colors[3] = *_gtk_css_rgba_value_get_rgba (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_BORDER_LEFT_COLOR));
 
-      _gtk_rounded_box_init_rect (&border_box, x, y, width, height);
-      _gtk_rounded_box_apply_border_radius_for_style (&border_box, style);
+      gtk_rounded_boxes_init_for_style (&border_box, NULL, NULL, style, x, y, width, height);
 
       render_border (cr, &border_box, border_width, colors, border_style);
     }
@@ -970,8 +969,7 @@ gtk_css_style_snapshot_border (GtkCssStyle *style,
       colors[2] = *_gtk_css_rgba_value_get_rgba (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_BORDER_BOTTOM_COLOR));
       colors[3] = *_gtk_css_rgba_value_get_rgba (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_BORDER_LEFT_COLOR));
 
-      _gtk_rounded_box_init_rect (&border_box, 0, 0, width, height);
-      _gtk_rounded_box_apply_border_radius_for_style (&border_box, style);
+      gtk_rounded_boxes_init_for_style (&border_box, NULL, NULL, style, 0, 0, width, height);
 
       snapshot_border (snapshot, &border_box, border_width, colors, border_style);
     }
diff --git a/gtk/gtkrenderprivate.h b/gtk/gtkrenderprivate.h
deleted file mode 100644 (file)
index 5c851c8..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-/* GTK - The GIMP Toolkit
- * Copyright (C) 2010 Carlos Garnacho <carlosg@gnome.org>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef __GTK_RENDER_PRIVATE_H__
-#define __GTK_RENDER_PRIVATE_H__
-
-#include <cairo.h>
-#include <pango/pango.h>
-#include <gdk/gdk.h>
-
-#include "gtkcssenumvalueprivate.h"
-
-void        gtk_render_content_path             (GtkStyleContext        *context,
-                                                 cairo_t                *cr,
-                                                 double                  x,
-                                                 double                  y,
-                                                 double                  width,
-                                                 double                  height);
-
-#endif /* __GTK_RENDER_PRIVATE_H__ */
index 11430c0a703dc0478d7e4b1cc8ab253e2b9e7b60..6c45067d168e31d34b8f21c2707948d1a9dd8d51 100644 (file)
@@ -20,6 +20,7 @@
 #include "gtkroundedboxprivate.h"
 
 #include "gtkcsscornervalueprivate.h"
+#include "gtkcssnumbervalueprivate.h"
 #include "gtkcsstypesprivate.h"
 #include "gtkstylecontextprivate.h"
 
@@ -121,17 +122,50 @@ _gtk_rounded_box_apply_border_radius (GskRoundedRect *box,
 }
 
 void
-_gtk_rounded_box_apply_border_radius_for_style (GskRoundedRect   *box,
-                                                GtkCssStyle      *style)
+gtk_rounded_boxes_init_for_style (GskRoundedRect *border_box,
+                                  GskRoundedRect *padding_box,
+                                  GskRoundedRect *content_box,
+                                  GtkCssStyle    *style,
+                                  double          x,
+                                  double          y,
+                                  double          width,
+                                  double          height)
 {
   GtkCssValue *corner[4];
+  GskRoundedRect box;
+
+  gsk_rounded_rect_init_from_rect (&box, &GRAPHENE_RECT_INIT (x, y, width, height), 0);
 
   corner[GSK_CORNER_TOP_LEFT] = gtk_css_style_get_value (style, GTK_CSS_PROPERTY_BORDER_TOP_LEFT_RADIUS);
   corner[GSK_CORNER_TOP_RIGHT] = gtk_css_style_get_value (style, GTK_CSS_PROPERTY_BORDER_TOP_RIGHT_RADIUS);
   corner[GSK_CORNER_BOTTOM_LEFT] = gtk_css_style_get_value (style, GTK_CSS_PROPERTY_BORDER_BOTTOM_LEFT_RADIUS);
   corner[GSK_CORNER_BOTTOM_RIGHT] = gtk_css_style_get_value (style, GTK_CSS_PROPERTY_BORDER_BOTTOM_RIGHT_RADIUS);
 
-  _gtk_rounded_box_apply_border_radius (box, corner);
+  _gtk_rounded_box_apply_border_radius (&box, corner);
+
+  if (border_box)
+    gsk_rounded_rect_init_copy (border_box, &box);
+
+  if (padding_box || content_box)
+    {
+      gsk_rounded_rect_shrink (&box,
+                               _gtk_css_number_value_get (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_BORDER_TOP_WIDTH), 100),
+                               _gtk_css_number_value_get (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_BORDER_RIGHT_WIDTH), 100),
+                               _gtk_css_number_value_get (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_BORDER_BOTTOM_WIDTH), 100),
+                               _gtk_css_number_value_get (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_BORDER_LEFT_WIDTH), 100));
+      if (padding_box)
+        gsk_rounded_rect_init_copy (padding_box, &box);
+
+      if (content_box)
+        {
+          gsk_rounded_rect_shrink (&box,
+                                   _gtk_css_number_value_get (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_PADDING_TOP), 100),
+                                   _gtk_css_number_value_get (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_PADDING_RIGHT), 100),
+                                   _gtk_css_number_value_get (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_PADDING_BOTTOM), 100),
+                                   _gtk_css_number_value_get (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_PADDING_LEFT), 100));
+          gsk_rounded_rect_init_copy (content_box, &box);
+        }
+    }
 }
 
 void
index 55f72d739a30c93bdb2c977fbd5116d261f284b1..4f9c0a169746313d121f1be41f0303da6740bf33 100644 (file)
@@ -33,9 +33,14 @@ void            _gtk_rounded_box_init_rect                      (GskRoundedRect
                                                                  double                  y,
                                                                  double                  width,
                                                                  double                  height);
-
-void            _gtk_rounded_box_apply_border_radius_for_style  (GskRoundedRect         *box,
-                                                                 GtkCssStyle            *style);
+void            gtk_rounded_boxes_init_for_style                (GskRoundedRect         *border_box,
+                                                                 GskRoundedRect         *padding_box,
+                                                                 GskRoundedRect         *content_box,
+                                                                 GtkCssStyle            *style,
+                                                                 double                  x,
+                                                                 double                  y,
+                                                                 double                  width,
+                                                                 double                  height);
 
 void            _gtk_rounded_box_apply_outline_radius_for_style (GskRoundedRect         *box,
                                                                  GtkCssStyle            *style);